import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		TOKEN: uni.getStorageSync("Authorization"),
		uid: '',
		sumPrice:0
	},
	mutations: {
		login(state, data) {
			uni.setStorageSync('Authorization', data.token)
			uni.setStorageSync('uid', data.id)
			state.TOKEN = data.token
			state.uid = data.id
			uni.navigateTo({
				url:"/pages/index/index"
			})
		},
		logout(state) {
			uni.removeStorageSync('Authorization')
			uni.removeStorageSync('uid')
			state.TOKEN = ''
			state.uid = ''
			uni.navigateTo({
				url:'/pages/login/login'
			})
		},
		setSumPrice(state,data){
			state.sumPrice = data
		}
	}
})
export default store
